<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - draw.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2008  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_DRAW_IMAGe_
<font color='#0000FF'>#define</font> DLIB_DRAW_IMAGe_

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='draw_abstract.h.html'>draw_abstract.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../algs.h.html'>../algs.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../pixel.h.html'>../pixel.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../matrix.h.html'>../matrix.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>cmath<font color='#5555FF'>&gt;</font>

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type,
        <font color='#0000FF'>typename</font> pixel_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='draw_line'></a>draw_line</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> x1,
        <font color='#0000FF'><u>long</u></font> y1,
        <font color='#0000FF'><u>long</u></font> x2,
        <font color='#0000FF'><u>long</u></font> y2,
        image_type<font color='#5555FF'>&amp;</font> c,
        <font color='#0000FF'>const</font> pixel_type<font color='#5555FF'>&amp;</font> val
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>x1 <font color='#5555FF'>=</font><font color='#5555FF'>=</font> x2<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// make sure y1 comes before y2
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>y1 <font color='#5555FF'>&gt;</font> y2<font face='Lucida Console'>)</font>
                <font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>y1,y2<font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>x1 <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> x1 <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> c.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font>;


            <font color='#009900'>// this is a vertical line
</font>            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> y <font color='#5555FF'>=</font> y1; y <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> y2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>y<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>y <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> y <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> c.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <font color='#0000FF'>continue</font>;

                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>c[y][x1], val<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>y1 <font color='#5555FF'>=</font><font color='#5555FF'>=</font> y2<font face='Lucida Console'>)</font>
        <b>{</b>

            <font color='#009900'>// make sure x1 comes before x2
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>x1 <font color='#5555FF'>&gt;</font> x2<font face='Lucida Console'>)</font>
                <font color='#BB00BB'>swap</font><font face='Lucida Console'>(</font>x1,x2<font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>y1 <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> y1 <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> c.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font>;

            <font color='#009900'>// this is a horizontal line
</font>            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> x <font color='#5555FF'>=</font> x1; x <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> x2; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>x<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>x <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> x <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> c.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <font color='#0000FF'>continue</font>;

                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>c[y1][x] , val<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> rise <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>y2<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>y1<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> run <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>x2<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>x1<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>rise<font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>run<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> slope <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>rise<font face='Lucida Console'>)</font><font color='#5555FF'>/</font>run;


                <font color='#0000FF'><u>double</u></font> first, last;


                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>x1 <font color='#5555FF'>&gt;</font> x2<font face='Lucida Console'>)</font>                
                <b>{</b>
                    first <font color='#5555FF'>=</font> x2;
                    last <font color='#5555FF'>=</font> x1;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    first <font color='#5555FF'>=</font> x1;
                    last <font color='#5555FF'>=</font> x2;
                <b>}</b>                             

                <font color='#0000FF'><u>long</u></font> y;
                <font color='#0000FF'><u>long</u></font> x;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> x1f <font color='#5555FF'>=</font> x1;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> y1f <font color='#5555FF'>=</font> y1;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font> i <font color='#5555FF'>=</font> first; i <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> last; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
                <b>{</b>   
                    y <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>slope<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>i<font color='#5555FF'>-</font>x1f<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> y1f<font face='Lucida Console'>)</font>;
                    x <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;


                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>y <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> y <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> c.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#0000FF'>continue</font>;

                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>x <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> x <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> c.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#0000FF'>continue</font>;


                    <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>c[y][x] , val<font face='Lucida Console'>)</font>;
                <b>}</b>         
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> slope <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>run<font face='Lucida Console'>)</font><font color='#5555FF'>/</font>rise;


                <font color='#0000FF'><u>double</u></font> first, last;


                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>y1 <font color='#5555FF'>&gt;</font> y2<font face='Lucida Console'>)</font>                
                <b>{</b>
                    first <font color='#5555FF'>=</font> y2;
                    last <font color='#5555FF'>=</font> y1;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    first <font color='#5555FF'>=</font> y1;
                    last <font color='#5555FF'>=</font> y2;
                <b>}</b>                             


                <font color='#0000FF'><u>long</u></font> x;
                <font color='#0000FF'><u>long</u></font> y;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> x1f <font color='#5555FF'>=</font> x1;
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> y1f <font color='#5555FF'>=</font> y1;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font> i <font color='#5555FF'>=</font> first; i <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> last; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
                <b>{</b>   
                    x <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>slope<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>i<font color='#5555FF'>-</font>y1f<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> x1f<font face='Lucida Console'>)</font>;
                    y <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;


                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>x <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> x <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> c.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#0000FF'>continue</font>;

                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>y <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> y <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> c.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#0000FF'>continue</font>;

                    <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>c[y][x] , val<font face='Lucida Console'>)</font>;
                <b>}</b> 
            <b>}</b>
        <b>}</b>

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type,
        <font color='#0000FF'>typename</font> pixel_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='draw_line'></a>draw_line</b> <font face='Lucida Console'>(</font>
        image_type<font color='#5555FF'>&amp;</font> c,
        <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p1,
        <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p2,
        <font color='#0000FF'>const</font> pixel_type<font color='#5555FF'>&amp;</font> val
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>p1.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,p1.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,p2.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,p2.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,c,val<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type,
        <font color='#0000FF'>typename</font> pixel_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='draw_rectangle'></a>draw_rectangle</b> <font face='Lucida Console'>(</font>
        image_type<font color='#5555FF'>&amp;</font> c,
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'>const</font> pixel_type<font color='#5555FF'>&amp;</font> val
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c, rect.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>tr_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, val<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c, rect.<font color='#BB00BB'>bl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>br_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, val<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c, rect.<font color='#BB00BB'>tl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>bl_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, val<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c, rect.<font color='#BB00BB'>tr_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>br_corner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, val<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type,
        <font color='#0000FF'>typename</font> pixel_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='draw_rectangle'></a>draw_rectangle</b> <font face='Lucida Console'>(</font>
        image_type<font color='#5555FF'>&amp;</font> c,
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'>const</font> pixel_type<font color='#5555FF'>&amp;</font> val,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>int</u></font> thickness
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> thickness; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>i<font color='#5555FF'>%</font><font color='#979000'>2</font><font face='Lucida Console'>)</font><font color='#5555FF'>=</font><font color='#5555FF'>=</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>draw_rectangle</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>shrink_rect</font><font face='Lucida Console'>(</font>rect,<font face='Lucida Console'>(</font>i<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>,val<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                <font color='#BB00BB'>draw_rectangle</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>grow_rect</font><font face='Lucida Console'>(</font>rect,<font face='Lucida Console'>(</font>i<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>,val<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_type,
        <font color='#0000FF'>typename</font> pixel_type
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='fill_rect'></a>fill_rect</b> <font face='Lucida Console'>(</font>
        image_type<font color='#5555FF'>&amp;</font> img,
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'>const</font> pixel_type<font color='#5555FF'>&amp;</font> pixel
    <font face='Lucida Console'>)</font>
    <b>{</b>
        rectangle area <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> area.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; r <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> area.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> area.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; c <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> area.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>img[r][c], pixel<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> image_array_type
        <font color='#5555FF'>&gt;</font>
    matrix<font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> image_array_type::value_type::type<font color='#5555FF'>&gt;</font> <b><a name='tile_images'></a>tile_images</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> image_array_type<font color='#5555FF'>&amp;</font> images
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> image_array_type::value_type::type T;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> matrix<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> size_nc <font color='#5555FF'>=</font> <font color='#BB00BB'>square_root</font><font face='Lucida Console'>(</font>images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> size_nr <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>size_nc<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>size_nc<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font>images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>? size_nc<font color='#5555FF'>-</font><font color='#979000'>1</font> : size_nc;
        <font color='#009900'>// Figure out the size we have to use for each chip in the big main image.  We will
</font>        <font color='#009900'>// use the largest dimensions seen across all the chips.
</font>        <font color='#0000FF'><u>long</u></font> nr <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <font color='#0000FF'><u>long</u></font> nc <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            nr <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>images[i].<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, nr<font face='Lucida Console'>)</font>;
            nc <font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>images[i].<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, nc<font face='Lucida Console'>)</font>;
        <b>}</b>

        matrix<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>temp</font><font face='Lucida Console'>(</font>size_nr<font color='#5555FF'>*</font>nr, size_nc<font color='#5555FF'>*</font>nc<font face='Lucida Console'>)</font>;
        T background_color;
        <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>background_color, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
        temp <font color='#5555FF'>=</font> background_color;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> <font color='#979000'>0</font>; r <font color='#5555FF'>&lt;</font> size_nr; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>r<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> c <font color='#5555FF'>=</font> <font color='#979000'>0</font>; c <font color='#5555FF'>&lt;</font> size_nc; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>c<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>idx <font color='#5555FF'>&lt;</font> images.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>set_subm</font><font face='Lucida Console'>(</font>temp, r<font color='#5555FF'>*</font>nr, c<font color='#5555FF'>*</font>nc, nr, nc<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#BB00BB'>mat</font><font face='Lucida Console'>(</font>images[idx]<font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#5555FF'>+</font><font color='#5555FF'>+</font>idx;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>return</font> temp;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_DRAW_IMAGe_
</font>




</pre></body></html>